<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ include file="../session.jsp"%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>
  	<script src="resources/js/jquery.js"></script>
	<script src="resources/js/bootstrap.min.js"></script>
  	<link href="resources/css/bootstrap_extend.css" rel="stylesheet" type="text/css" />
	<script src="resources/js/scripts/innovaeditor.js" type="text/javascript"></script>
	<script src="resources/js/scripts/innovamanager.js" type="text/javascript"></script>
	<script type="text/javascript">
	    $(document).ready(function () {
	        $('#commonText').liveEdit({
	            height: 350,
	            //css: ['resources/css/bootstrap.min.css', 'resources/css/bootstrap_extend.css'] /* Apply bootstrap css into the editing area */,
	            groups: [
	                    ["group1", "", ["Bold", "Italic", "Underline", "ForeColor", "RemoveFormat"]],
	                    ["group2", "", ["Bullets", "Numbering", "Indent", "Outdent"]],
	                    ["group3", "", ["Paragraph", "FontSize", "FontDialog", "TextDialog"]],
	                    ["group4", "", ["LinkDialog", "ImageDialog", "TableDialog", "Emoticons", "Snippets"]],
	                    ["group5", "", ["Undo", "Redo", "FullScreen", "SourceDialog"]]
	                    ] /* Toolbar configuration */
	        });
	
	        $('#commonText').data('liveEdit').startedit();
	    });
	</script>
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header">
			<h2>기타게시글 수정</h2>
		</div>

		<form id="editEtc" class="form-horizontal" role="form" method="post">
			<fieldset>
			
				<input type="hidden" name="idCommon" value="${item.idCommon}" />
				<input type="hidden" name="page" value="${page}" />
				
				<div class="form-group">
					<label for="isDisplay" class="col-md-2 control-label">전시여부</label>
					<div class="col-md-10">
						<label class="radio-inline">
							<input type="radio" name="isDisplay" value="1" <c:if test="${item.isDisplay == 1}">checked</c:if>> 활성
						</label>
						<c:if test="${item.idCommon != 1 && item.idCommon != 2}">
							<label class="radio-inline">
								<input type="radio" name="isDisplay" value="0" <c:if test="${item.isDisplay == 0}">checked</c:if>> 비활성
							</label>
						</c:if>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-md-2 control-label">번호</label>
					<div class="col-md-10">
						<p class="form-control-static">${item.idCommon}</p>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-md-2 control-label">수정시간</label>
					<div class="col-md-10">
						<p class="form-control-static">
							<fmt:parseDate value="${item.editDate.substring(0, 12)}" var="dateFmt" pattern="yyyyMMddHHmm"/>
                            <fmt:formatDate value="${dateFmt}" pattern="yyyy-MM-dd HH:mm"/>
						</p>
					</div>
				</div>
			
				<div class="form-group">
					<label for="commonTitle" class="col-md-2 control-label">제목</label>
					<div class="col-md-10">
						<c:choose>
							<c:when test="${item.idCommon == 1 || item.idCommon == 2}">
								<p class="form-control-static">${item.commonTitle}</p>
								<input type="hidden" name="commonTitle" value="${item.commonTitle}" />
							</c:when>
							<c:otherwise>
								<input type="text" class="form-control" name="commonTitle" placeholder="제목을 입력하세요" value="${item.commonTitle}" />
							</c:otherwise>
						</c:choose>
					</div>
				</div>
				
				<div class="form-group">
					<label for="commonText" class="col-md-2 control-label">내용</label>
					<div class="col-md-10">
						<textarea id="commonText" name="commonText" class="form-control">${item.commonText}</textarea>
					</div>
				</div>
				
				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<c:if test="${item.idCommon == 1 || item.idCommon == 2}">
								<div class="col-md-6">
									<button type="submit" id="editEtcOk" class="btn btn-primary btn-block" formaction="editEtcOk">수정하기</button>
								</div>
								<div class="col-md-6">
									<button type="reset" class="btn btn-warning btn-block">다시작성</button>
								</div>
							</c:if>
							<c:if test="${item.idCommon != 1 && item.idCommon != 2}">
								<div class="col-md-4">
									<button type="submit" id="editEtcOk" class="btn btn-primary btn-block" formaction="editEtcOk">수정하기</button>
								</div>
								<div class="col-md-4">
									<button type="reset" class="btn btn-warning btn-block">다시작성</button>
								</div>
								<div class="col-md-4">
									<button type="submit" id="deleteEtcOk" class="btn btn-danger btn-block" formaction="deleteEtcOk">삭제하기</button>
								</div>
							</c:if>
						</div>

					</div>
				</div>
			</fieldset>
		</form>
	</div>
	
	<!-- 형식검사 클래스 참조 -->
	<script src="resources/js/string.js"></script>
	<script type="text/javascript">
		$(function() {
			
			$("#deleteEtcOk").click(function() {
				if (!confirm("정말 삭제 하시겠습니까?")) {
					return false;
				}
			});
			
			$("#editEtcOk").click(function() {
				
				if (!$("input[name='isDisplay']").is(":checked")) {
					alert("전시여부를 선택해 주세요");
					$("input[name='isDisplay']").focus();
					return false;
				}
				
				if (!$("input[name='commonTitle']").val().isValue()) {
					alert("제목을 입력하세요.");
					$("input[name='commonTitle']").focus();
					return false;
				}
				
				var sHtml = $('#commonText').data('liveEdit').getXHTMLBody();
				if (sHtml == "\n" || sHtml == "") {
					alert("내용을 입력하세요.");
					$("textarea[name='commonText']").focus();
					return false;
				}
				
				if (!confirm("정말 수정 하시겠습니까?")) {
					return false;
				}
			});
		});
	</script>
  </body>
</html>